function findAllOccurrences(word, text, caseInsensitive)
{
    var result = [],
        wordAsString = word.toString(),
        textAsString = text.toString(),
        indexOfOccurrence = -2,
        positionToCheckFrom = 0;

    if (caseInsensitive === true)
    {
        wordAsString = wordAsString.toLowerCase();
        textAsString = textAsString.toLowerCase();
    }

    while (indexOfOccurrence !== -1)
    {
        indexOfOccurrence = textAsString.indexOf(wordAsString, positionToCheckFrom);

        if (indexOfOccurrence > -1)
        {
            positionToCheckFrom = indexOfOccurrence + 1;
            result.push(indexOfOccurrence);
        }
    }

    return result;
}

console.log(findAllOccurrences("and", "The world is nice and beautiful full of life and joy"));
console.log(findAllOccurrences("and", "The world is nice And beautiful full of life and joy"));
console.log(findAllOccurrences("and", "The world is nice And beautiful full of life and joy", true));